import random

WIDTH = 300
HEIGHT = 300

BACK_COLOR = (0, 0, 0)

class MyCircle:
    def __init__(self, x, y, r):
        self.x = x
        self.y = y
        self.r = r 
        self.clr = clr
        self.spd_x = 1
        self.spd_y= 1
    def SetSpeed(self, spd_x, spd_y):
        self.spd_x = spd_x
        self.spd_y = spd_y
        
    def Update(self):
        self.x += self.spd_x
        self.y += self.spd_y
        if (self.x + self.r > WIDTH) or (self.x - self.r < 0):
            self.spd_x = -(self.spd_x + self.spd_x * (random.random() - 0.5))
            # self.spd_x += self.spd_x * (random.random() - 0.5)
        elif (self.y + self.r > HEIGHT) or (self.y - self.r < 0):
            self.spd_y = -(self.spd_y + self.spd_y * (random.random() - 0.5))
            # self.spd_y += self.spd_y * (random.random()- 0.5)
        
        if self.x + self.r > WIDTH:
            self.x = WIDTH - self.r
        elif self.x - self.r < 0:
            self.x = self.r

        if self.y +self.r > HEIGHT:
            self.y = HEIGHT - self.r
        elif self.y - self.r < 0:
            self.y = self.r
        
    def Draw(self):
        screen.draw.filled_circle((self.x, self.y), self.r, self.clr)

clr_list = [
    (0, 200, 0),
    (200, 0, 0),
    (0, 0, 200),
    (0, 200, 200),
    (200, 0, 200),
    (200, 200, 0),
    (200, 200, 200),
]
circle_list = []
for i in range(10):
    r = random.randint(10, 30)
    clr_index = random.randint(0, 6)
    #print(clr_index)
    clr = clr_list[clr_index]
    circle = MyCircle(random.randint(50, 150), random.randint(50, 150), r)
    circle.SetSpeed(random.randint(1, 5), random.randint(1, 5))
    circle_list.append(circle)

def on_key_down(key):
    if key == keys.ESCAPE:
        quit()
        
def on_mouse_move(pos):
    print("mouse_down", pos)
        
def on_mouse_down(pos):
    print("mouse_down", pos)
    
def on_mouse_up(pos):
    print("mouse_up", pos)
    
def update():
    for c in circle_list:
        c.Update()
        
def draw():
    screen.clear()
    screen.fill(BACK_COLOR)
    for c in circle_list:
        c.Draw()


